package Demo428;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

    public class TcpClient {
        public static void main(String[] args) {
            Socket client=null;
            PrintWriter out=null;
            BufferedReader reader=null;
            try {
                client=new Socket("192.168.10.225",7890);

                out=new PrintWriter(client.getOutputStream(),true);
                reader=new BufferedReader(new InputStreamReader(client.getInputStream(),"UTF-8"));
                Scanner input=new Scanner(System.in);
                while(true){
                    String message=input.nextLine();
                    out.println(message);
                    out.flush();
                    String response=reader.readLine();
                    System.out.println(response);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                if(client!=null){
                    try {
                        client.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

